//
//  XMWithdrawViewController.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/16.
//

#import "XMWithdrawViewController.h"
#import "XMWithdrawView.h"
#import "XMNetwork+mine.h"
#import "XMNetwork+login.h"

#import "XMWithdrawDetailViewController.h"
#import "XMBandBankCardViewController.h"
#import "XMServiceInfoViewController.h"
#import <WXApi.h>

@interface XMWithdrawViewController ()<XMWithdrawViewDelegate, WXApiDelegate>

@property (nonatomic, strong) XMWithdrawView *withdrawView;

@end

@implementation XMWithdrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatUI];
}

- (void)creatUI {
    [self.view addSubview:self.withdrawView];
    [self getBalance];
}

//余额
- (void)getBalance {
    XMWeakSelf;
    [_Network getBalanceSuccess:^(id  _Nonnull responseObject) {
        [weakSelf.withdrawView setUserBalance:[responseObject objectForKey:@"data"]];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//提现
- (void)withdrawActionWithPayType:(NSString *)payType
                       payAccount:(NSString *)payAccountStr
                            money:(NSString *)money {
    [_Network withdrawWithMoney:money
                        payType:payType
                     payAccount:payAccountStr
                        success:^(id  _Nonnull responseObject) {
        [MBProgressHUD showSuccess:@"提现成功"];
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

#pragma mark - Delegate
//绑卡
- (void)bandBankCardAction {
    XMBandBankCardViewController *bandBankVC = [[XMBandBankCardViewController alloc] init];
    [self.navigationController pushViewController:bandBankVC animated:YES];
}

//提现
- (void)withdrawActionWithPayType:(NSString *)payType
                      payAccmount:(NSString *)payAccount
                            money:(NSString *)money {
//    [WXApi registerApp:@"wxe27fd4207b87851f" universalLink:@"https://help.wechat.com/zmy/"];
//    SendAuthReq *req = [[SendAuthReq alloc] init];
//    req.scope = @"snsapi_userinfo";
//    req.state = @"com.xmjj_zmy";
//    [WXApi sendReq:req completion:^(BOOL success) {
//
//    }];
    [self withdrawActionWithPayType:@"1" payAccount:@"" money:money];
}

- (void)onResp:(BaseResp *)resp {
    if (!resp.errStr || resp.errStr.length == 0) {
        [self getWeichatInfoWithRespcode:((SendAuthResp *)resp).code];
    }
}

- (void)getWeichatInfoWithRespcode:(NSString *)respcode {
    MJWeakSelf;
    [_Network getWechatInfoWithRespcode:respcode
                                success:^(id  _Nonnull responseObject) {
        NSString *errerrcode = [responseObject safeStringForKey:@"errcode"];
        if (!errerrcode || errerrcode.length == 0) {
//            [weakSelf loginWithWeichatUnionid:[responseObject safeStringForKey:@"unionid"]];
        }
        else {
            [MBProgressHUD showError:[responseObject safeStringForKey:@"errmsg"]];
        }
    } failure:^(NSError * _Nonnull error) {
        
    }];
}

//提现详情
- (void)checkWithdrawDetailAction {
    XMWithdrawDetailViewController *withdrawDetailVC = [[XMWithdrawDetailViewController alloc] init];
    [self.navigationController pushViewController:withdrawDetailVC animated:YES];
}

//提现说明
- (void)checkWithdrawExplainAction {
    XMServiceInfoViewController *serviceInfoVC = [[XMServiceInfoViewController alloc] init];
    serviceInfoVC.type = @"6";
    serviceInfoVC.titleStr = @"提现说明";
    [self.navigationController pushViewController:serviceInfoVC animated:YES];
}

//服务条款
- (void)checkServiceAction {
    XMServiceInfoViewController *serviceInfoVC = [[XMServiceInfoViewController alloc] init];
    serviceInfoVC.type = @"4";
    serviceInfoVC.titleStr = @"服务条款";
    [self.navigationController pushViewController:serviceInfoVC animated:YES];
}

//隐私条款
- (void)checkPrivacyAction {
    XMServiceInfoViewController *serviceInfoVC = [[XMServiceInfoViewController alloc] init];
    serviceInfoVC.type = @"5";
    serviceInfoVC.titleStr = @"隐私政策";
    [self.navigationController pushViewController:serviceInfoVC animated:YES];
}

#pragma mark - Init
- (XMWithdrawView *)withdrawView {
    if (!_withdrawView) {
        _withdrawView = [[XMWithdrawView alloc] initWithFrame:self.view.bounds];
        _withdrawView.delegate = self;
    }
    return _withdrawView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
